home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
video
/
trojka.tgz
/
trojka.tar
/
trojka
/
screen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-25
|
7KB
|
448 lines
/*
* @(#) screen.c -- Screen oriented routines for TROJKA
* created: 4.iii.1992
* last update: 16.iv.1992
*/
#include <stdio.h>
#include <curses.h>
#include "sys_custom.h"
#include "trojka.h"
#include "screen.h"
#include "hiscore.h"
int makeblock(), wipeblock(), makestars(),
showscore(), showtrojka(), showspeed(),
showmesg(), showgameover(),
titlescreen(), listscores(),
build(), redraw(), drawfield(),
statistics(), selectspeed(),
getname(), dropchar(), backspace();
extern struct scorefile *sfile;
extern flag
quit; /* all defined in trojka */
extern int
block_count[],
xloc[],
yloc[],
blockwidth,
stacklevel,
position,
x_min,
x_max,
statx,
speed;
extern unsigned long
score,
wipes,
blocks;
extern char field[VIRT_XSIZE][VIRT_YSIZE];
static char TITLE[7][40] = {
" **",
"***** **** *** * * * * * ",
" * * * * * * ** * * * * ",
" * **** * * * * * ** * *",
" * * * * ** * * * *****",
" * * *** * * * * * *",
" T R O J K A "
};
static char mesg[MESGS][40] = {
"You're doin' well",
"You're playing ok",
"You're doin' fine",
"You're playing good",
"You're playing great",
"You're playing very good",
"You're really are good at this",
"You're a champion",
"You're a trojka-professional",
"You've played this before, haven't ya?",
"Hey, I hope you're not cheating!",
"What a magnificent score",
"You're kinda addicted...",
"You're a MEGA-player",
"What time is it, by the way?",
"You're a trojka-czar",
"I'm very tired",
"You must be paranoid..",
"I give up giving comments. Enjoy!"
};
static char block80[BLOCKS+1][5] =
{
" ",
"OOOO",
"||||",
"XXXX",
"%%%%",
"$$$$"
}; /* used in mono */
int makeblock(x, y, shape) /* create a block */
int x, y, shape;
{
movexy(xloc[x], yloc[y]);
qprintf("%4s",block80[shape]);
}
int wipeblock(x, y) /* remove block */
int x, y;
{
movexy(xloc[x], yloc[y]);
qprintf(SPACE80);
}
int makestars(x, y) /* show stars */
int x, y;
{
movexy(xloc[x], yloc[y]);
qprintf(WIPE80);
}
int showscore()
{
movexy(SCORE_X, SCORE_Y+1);
qprintf("%7lu",score);
refresh();
}
int showtrojka(bonus)
int bonus;
{
movexy(x_min, BONUS_Y);
qprintf("TROJKA! %5lu",
(unsigned long)(1111*bonus)
);
refresh();
delay(1000);
movexy(x_min, BONUS_Y); qprintf(" ");
refresh();
}
int showspeed(s)
int s;
{
movexy(SPEED_X+3, SPEED_Y+1); qprintf("%u",s);
refresh();
}
int showmesg(n)
int n;
{
movexy((80 - strlen(mesg[n])) / 2, MESG_Y);
qprintf("%s",mesg[n]);
refresh();
}
int wipemesg()
{
movexy(1, MESG_Y);
clreol();
refresh();
}
int showgameover()
{
movexy(x_min,10);
qprintf(" G A M E O V E R ");
refresh();
delay(1500);
}
int handletrojka(trojka_count)
int trojka_count;
{
showtrojka(trojka_count);
score += (unsigned long)(trojka_count * 1111);
showscore();
}
int titlescreen() /* title screen */
{
char c;
int i;
clear_scr();
for(i = 0; i < 7;i++) {
movexy(1,i +6);
qprintf("%s",TITLE[i]);
}
movexy(1,i + 13);
qprintf("KEEP PLAYING TROJKA");
readscores(); /* re-read scores */
listscores();
movexy(1,1);
refresh();
killkeys();
c = getch();
if(c == QUIT)
quit = TRUE;
clear_scr();
}
int listscores()
{
int j;
flag hilite;
struct scorefile *eof, *i;
eof = &sfile[NUMSCORES-1];
j = 0;
hilite = 0;
movexy(HISCORE_X,1); qprintf("Best Trojka-Czars");
for(i=sfile; i<eof; i++) {
if (j == position-1) {
hilite = 1;
standout();
/* hilight */
}
movexy(HISCORE_X, j+3);
qprintf("%-22s %7lu %3d",
i->name,
i->points,
i->stage
);
if(hilite == 1) {
standend();
/* unhilight */
hilite = 0;
}
j++;
}
if(position >= NUMSCORES) {
movexy(HISCORE_X, 24);
qprintf("%-22s %7lu %3d",
"You",
score,
speed
);
}
}
int build()
{
int x, y, left, right;
left = x_min - 1;
right = x_max + blockwidth;
clear_scr();
for(y = SCR_TOP + 1; y <= BOTTOM; y++) {
movexy(left, y);
qprintf("#");
movexy(right, y);
qprintf("#");
}
for(x = left; x <= right; x++)
{
movexy(x, BOTTOM + 1);
qprintf("#");
}
movexy(SCORE_X, SCORE_Y); qprintf("-SCORE-");
movexy(SPEED_X, SPEED_Y); qprintf("-SPEED-");
movexy(statx, SUM_Y); qprintf("S U M");
movexy(statx, WIPES_Y); qprintf("* * *");
movexy(statx, 1); qprintf("Statistics");
for(y = 0; y < BLOCKS; y++) {
movexy(statx, (y * 2) + 3);
qprintf("%4s",block80[y+1]);
}
movexy(SPEED_X+3, SPEED_Y+1); qprintf("%u",speed);
refresh();
}
int redraw()
{
int x, y, left, right;
left = x_min - 1;
right = x_max + blockwidth;
clear_scr();
for(y = SCR_TOP + 1; y <= BOTTOM; y++) {
movexy(left, y);
qprintf("#");
movexy(right, y);
qprintf("#");
}
for(x = left; x <= right; x++)
{
movexy(x, BOTTOM + 1);
qprintf("#");
}
movexy(SCORE_X, SCORE_Y); qprintf("-SCORE-");
movexy(SPEED_X, SPEED_Y); qprintf("-SPEED-");
movexy(statx, SUM_Y); qprintf("S U M");
movexy(statx, WIPES_Y); qprintf("* * *");
movexy(statx, 1); qprintf("Statistics");
for(y = 0; y < BLOCKS; y++) {
movexy(statx, (y * 2) + 3);
qprintf("%4s",block80[y+1]);
}
drawfield();
refresh();
}
int drawfield()
{
int x,y;
for(x = 0; x < VIRT_XSIZE;x++)
for(y = PLM_TOP; y >= PLM_BOTTOM; y--)
makeblock(x,y,field[x][y]);
}
int statistics()
{
int y, perc, x;
x = statx + 6;
movexy(statx, WIPES_Y+1); qprintf("%5lu",wipes);
movexy(statx, SUM_Y+1); qprintf("%5lu",blocks);
for(y = 0; y < BLOCKS; y++) {
perc = (block_count[y] * 100) / blocks;
movexy(x, (( y * 2 ) + 3) );
qprintf("%4d %%", perc);
}
refresh();
}
int selectspeed() /* get starting speed */
{
char c;
movexy(10, 12);
qprintf("Select game-speed (0...9) --->");
refresh();
killkeys(); /* flush keyboard buffer */
c = getch();
if (c == QUIT) /* if QUIT-key is pressed.. */
quit = TRUE; /* ..quit the game */
else {
if((c >= '0') && (c <= '9'))
return c-'0';
return 5 ;
}
}
int getname(tag)
char tag[];
{
int x, xstart, name_len;
char c;
name_len = 20;
x = c = 0;
xstart = (80-name_len) / 2;
clear_scr();
movexy(xstart, SCORE_Y);
qprintf("Score: %7lu", score);
movexy(xstart, SCORE_Y + 3);
qprintf("Enter your name please:");
movexy(xstart, TAG_Y);
qprintf("....................");
movexy(xstart + x, TAG_Y);
refresh();
killkeys();
c = getch();
movexy(26,SCORE_Y); clreol();
movexy(26,SCORE_Y + 3); clreol();
refresh();
while((c != CR) && (c != LF)) {
movexy(xstart + x, TAG_Y);
refresh();
if ((c >= ' ') && (c <= '~') && (x < name_len)) {
dropchar(xstart + x, (tag[x] = c));
x++;
} else if((c == BACKSP) && (x > 0)) {
x--;
backspace(xstart + x, tag[x]);
tag[x] = '\0';
movexy(xstart + x, TAG_Y);
qprintf(".");
movexy(xstart + x, TAG_Y);
refresh();
}
c = getch();
}
tag[x] = '\0';
return(x);
}
int dropchar(x,c)
int x;
char c;
{
int y;
for(y = SCR_TOP + 1; y <= TAG_Y; y++) {
movexy(x, y-1); qprintf(" ");
movexy(x, y); qprintf("%c",c);
refresh();
}
}
int backspace(x, c)
int x;
char c;
{
int y;
for(y = TAG_Y; y < SCR_BOT - 1; y++) {
movexy(x, y); qprintf("%c",c);
refresh();
movexy(x, y); qprintf(" ");
refresh();
}
}